import Vue from 'vue'
import App from './App.vue'

import axios from 'axios';
import ElementUI from 'element-ui';
import VueI18n from 'vue-i18n';
import store from  './store'
import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
import "babel-polyfill";
//自定义样式
import './assets/cdn/font_830376_qzecyukz0s.css';
import './assets/css/icon.css';
import './assets/css/iconfont/iconfont.js';
import './assets/iconfont/iconfont.js';
//自定义指令
import './components/common/directives';

//自定义函数
import constant from './utils/constant';
import commonutils from './utils/commonUtils';
import {post,fetch,patch,put,del,download,fetchImg} from './utils/http';
//自定义组件
import fancyAddress from './components/common/form/index.js';


//路由
import router from './router'

Vue.config.productionTip = false
Vue.use(VueI18n);
Vue.use(fancyAddress);
Vue.use(ElementUI, {
    size: 'small'
});

Vue.prototype.$axios = axios;
Vue.prototype.$constant = constant;
Vue.prototype.$common = commonutils;
Vue.prototype.$post = post;
Vue.prototype.$fetch = fetch;
Vue.prototype.$patch = patch;
Vue.prototype.$put = put;
Vue.prototype.$delete = del;
Vue.prototype.$download = download;
Vue.prototype.$fetchImg = fetchImg;



// const i18n = new VueI18n({
//     locale: 'zh',
//     messages
// })

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    if (!localStorage.token && to.path !== '/login') {
        next('/login');
    }else {
        // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
        if (navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor') {
            Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
                confirmButtonText: '确定'
            });
        } else {
            //权限验证
            if(to.path !== '/login'){
                fetch('/api/auth/login/checkPermission',{
                    permissionPath:to.path
                }).then((res)=>{
                    if(res.data){
                        next();    
                    }else{
                        next("/403")
                    }
                })
            }else{
                next();
            }
        }
    }
})


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')